package base

import "jvmgo/ch09/rtda"

type Instruction interface {
    FetchOperands(reader *BytecodeReader)
    Execute(frame *rtda.Frame)
}

//无操作数指令
type NoOperandsInstruction struct {
    // empty
}

func (self *NoOperandsInstruction) FetchOperands(reader *BytecodeReader) {
    // nothing to do
}

//跳转指令
type BranchInstruction struct {
    Offset int
}

func (self *BranchInstruction) FetchOperands(reader *BytecodeReader) {
    self.Offset = int(reader.ReadInt16())
}

//存储和加载类指令，类指令有8位索引值
type Index8Instruction struct {
    Index uint
}

func (self *Index8Instruction) FetchOperands(reader *BytecodeReader) {
    self.Index = uint(reader.ReadUint8())
}

//存储和加载需要访问常量池的指令，常量池索引为16位
type Index16Instruction struct {
    Index uint
}

func (self *Index16Instruction) FetchOperands(reader *BytecodeReader) {
    self.Index = uint(reader.ReadUint16())
}
